import { defaultTestTaskOption, TestTaskOption } from '../../task-builder/test-task-option';
import { AbilityType, APIType, APIVersion, LanguageType, ModuleTemplateType, RuntimeOSType, SDKType } from './constants';

/**
 * Project模板通用选项
 */
export interface ProjectTemplateOption {
  /**
   * SDK类型 单框架/双框架
   */
  sdk: SDKType;

  /**
   * 运行时 HarmonyOS/OpenHarmony
   */
  runtimeOS: RuntimeOSType;

  /**
   * api 版本
   */
  apiVersion: APIVersion;

  /**
   * 模型类型
   */
  apiType: APIType;

  /**
   * 语言
   */
  language: LanguageType;

  /**
   * 能力类型 应用/原子化服务
   */
  abilityType: AbilityType;

  /**
   * entry模块模板类型
   */
  entryTemplateType: ModuleTemplateType;
}

export type ProjectTemplateIndex = Pick<ProjectTemplateOption, 'apiVersion' | 'apiType' | 'abilityType'>;

export const defaultProjectTemplateOption: ProjectTemplateOption = {
  /**
   * SDK类型 单框架/双框架
   */
  sdk: SDKType.Single,

  /**
   * 运行时 HarmonyOS/OpenHarmony
   */
  runtimeOS: RuntimeOSType.HarmonyOS,

  /**
   * api 版本
   */
  apiVersion: APIVersion.API10,

  /**
   * 模型类型
   */
  apiType: APIType.STAGE,

  /**
   * 语言
   */
  language: LanguageType.ArkTs,

  /**
   * 能力类型 应用/原子化服务
   */
  abilityType: AbilityType.Application,

  /**
   * 默认entry模块
   */
  entryTemplateType: ModuleTemplateType.EmptyAbility,
};

export const defaultProjectIndex: ProjectTemplateIndex = {
  /**
   * api 版本
   */
  apiVersion: APIVersion.API10,

  /**
   * 模型类型
   */
  apiType: APIType.STAGE,

  /**
   * 能力类型 应用/原子化服务
   */
  abilityType: AbilityType.Application,
};

/**
 * 工程模板选项构建类
 */
export class ProjectTemplateOptionBuilder {
  private readonly _option: ProjectTemplateOption;

  private constructor() {
    this._option = { ...defaultProjectTemplateOption };
  }

  public static builder(): ProjectTemplateOptionBuilder {
    return new ProjectTemplateOptionBuilder();
  }

  public static defaultOpt(): ProjectTemplateOption {
    return { ...defaultProjectTemplateOption };
  }

  sdk(sdk: SDKType) {
    this._option.sdk = sdk;
    return this;
  }

  runtimeOS(runtimeOS: RuntimeOSType) {
    this._option.runtimeOS = runtimeOS;
    return this;
  }

  apiVersion(apiVersion: APIVersion) {
    this._option.apiVersion = apiVersion;
    return this;
  }

  apiType(apiType: APIType) {
    this._option.apiType = apiType;
    return this;
  }

  language(language: LanguageType) {
    this._option.language = language;
    return this;
  }

  abilityType(abilityType: AbilityType) {
    this._option.abilityType = abilityType;
    return this;
  }

  entryTemplateType(entryTemplateType: ModuleTemplateType) {
    this._option.entryTemplateType = entryTemplateType;
    return this;
  }

  build() {
    return this._option;
  }
}

/**
 * module模板通用选项
 */
export interface ModuleTemplateOption {
  /**
   * 运行时 HarmonyOS/OpenHarmony
   */
  runtimeOS: RuntimeOSType;

  /**
   * api 版本
   */
  apiVersion: APIVersion;

  /**
   * 模型类型
   */
  apiType: APIType;

  /**
   * 模块类型，entry、feature、shared、har
   */
  moduleTemplateType: ModuleTemplateType;

  /**
   * 语言
   */
  language: LanguageType;

  /**
   * 能力类型 应用/原子化服务
   */
  abilityType: AbilityType;
}

// eslint-disable-next-line max-len
export type ModuleTemplateIndex = Pick<ModuleTemplateOption, 'apiVersion' | 'apiType' | 'abilityType' | 'moduleTemplateType'>;

/**
 * ModuleTemplateOption默认选项
 *
 */
export const defaultModuleTemplateOption: ModuleTemplateOption = {
  /**
   * 运行时 HarmonyOS/OpenHarmony
   */
  runtimeOS: RuntimeOSType.HarmonyOS,

  /**
   * api 版本
   */
  apiVersion: APIVersion.API10,

  /**
   * 模型类型
   */
  apiType: APIType.STAGE,

  /**
   * 模块的模板类型
   */
  moduleTemplateType: ModuleTemplateType.EmptyAbility,

  /**
   * 语言
   */
  language: LanguageType.ArkTs,

  /**
   * 能力类型 应用/原子化服务
   */
  abilityType: AbilityType.Application,
};

export const defaultModuleIndex: ModuleTemplateIndex = {
  /**
   * api 版本
   */
  apiVersion: APIVersion.API10,

  /**
   * 模型类型
   */
  apiType: APIType.STAGE,

  /**
   * 模块的模板类型
   */
  moduleTemplateType: ModuleTemplateType.EmptyAbility,

  /**
   * 能力类型 应用/原子化服务
   */
  abilityType: AbilityType.Application,
};

/**
 * 模块模板选项构建类
 */
export class ModuleTemplateOptionBuilder {
  private readonly _option: ModuleTemplateOption;

  private constructor() {
    this._option = { ...defaultModuleTemplateOption };
  }

  public static builder(): ModuleTemplateOptionBuilder {
    return new ModuleTemplateOptionBuilder();
  }

  public static defaultOpt(): ModuleTemplateOption {
    return { ...defaultModuleTemplateOption };
  }

  runtimeOS(runtimeOS: RuntimeOSType) {
    this._option.runtimeOS = runtimeOS;
    return this;
  }

  apiVersion(apiVersion: APIVersion) {
    this._option.apiVersion = apiVersion;
    return this;
  }

  apiType(apiType: APIType) {
    this._option.apiType = apiType;
    return this;
  }

  moduleTemplateType(moduleTemplateType: ModuleTemplateType) {
    this._option.moduleTemplateType = moduleTemplateType;
    return this;
  }

  language(language: LanguageType) {
    this._option.language = language;
    return this;
  }

  abilityType(abilityType: AbilityType) {
    this._option.abilityType = abilityType;
    return this;
  }

  build() {
    return this._option;
  }
}

export type TaskTags = { caseName?: string | Array<string> } & ProjectTemplateOption & TestTaskOption;

export type FilterOption<T> = {
  [K in keyof Partial<T>]: (val: string) => boolean;
};

export const defaultTaskTag: TaskTags = {
  caseName: 'default-case-name',
  ...defaultProjectTemplateOption,
  ...defaultTestTaskOption,
};
